#ifndef DBENVIMPL_H_
#define DBENVIMPL_H_

#include "status.hxx"


class DbEnvImpl;

#define LOG_SYNC       0x0001
#define LOG_HAS_DATA   0x0002
#define LOG_NO_DATA    0x0004

/**
 * The DbEnv object manages a database environment including support for locking, redo log and datastores. 
 * Methods of the DbEnv object are used to configure the environment as well as 
 * to operate on subsystems and datastores in the environment.  
 */

class DbEnv {

private:
    DbEnvImpl* m_envImpl;

    //env home directory
    std::string m_home;

    //log directory
    std::string m_logdir;

    //redo-log buffer size
    uint32_t m_lgBufSize;

    //logging file for message 
    std::string m_logmsgFile;
    
public:
    /**
     * Construct a DbEnv object.
     * @param: home, home directory for db environment
     * @param: logpath, log directory for redo-log
     * @param: logmsgFile, message logging file name
     * @param: lgBufSize, redo-log buffer size(byte)
     */
    DbEnv(const std::string& home, 
          const std::string& logpath, 
          const std::string& logmsgFile, 
          uint32_t lgBufSize);

    virtual ~DbEnv();

    /**
     * Open a db environment
     * @param: flag, the value of flag can be one of: LOG_SYNC, LOG_HAS_DATA,
     * LOG_NO_DATA. The default value is LOG_HAS_DATA.
     */ 
    virtual DbStatus open(uint32_t flag = LOG_HAS_DATA);
    
    //close a dbenv
    virtual DbStatus close();
    
    //start a dbenv.
    virtual DbStatus start();

    //write log and all of data to disk
    virtual DbStatus sync();

    //write log or data to disk 
    virtual DbStatus flushlog();

    virtual std::string getHomepath();
    virtual std::string getLogpath();
    virtual void setLogBufferSize(uint32_t size);
    virtual uint32_t getLogBufferSize();

    //start compact. Compaction is disabled by default
    virtual void startCompact();

    //stop compact
    virtual void stopCompact();

private:
    DbEnv(const DbEnv&);
    DbEnv& operator=(const DbEnv&);

    friend class DataStore;
};

#endif
